package com.atom.test.db.sqldelight

import android.annotation.SuppressLint
import android.content.Context
import com.squareup.sqldelight.android.AndroidSqliteDriver
import com.squareup.sqldelight.db.SqlDriver


@SuppressLint("StaticFieldLeak")
object SQLDeLightModuleApplication {

    private lateinit var context: Context

    fun init(context: Context) {
        this.context = context
        initDB()
    }

    private lateinit var driver: SqlDriver

    fun initDB() {
        driver = AndroidSqliteDriver(Database.Schema, context, "test.db")
    }

    fun test() {
        val database = Database(driver)

        val playerQueries: PlayerQueries = database.playerQueries

        println(playerQueries.selectAll().executeAsList())
        // Prints [HockeyPlayer(15, "Ryan Getzlaf")]

        playerQueries.insert(player_number = 10, full_name = "Corey Perry")
        println(playerQueries.selectAll().executeAsList())
        // Prints [HockeyPlayer(15, "Ryan Getzlaf"), HockeyPlayer(10, "Corey Perry")]

        val player = HockeyPlayer(10, "Ronald McDonald")
        playerQueries.insertFullPlayerObject(player)
    }
}